<?php

defined('_JEXEC') or die;

class TourModeltourcategories extends JModelList {

    public function __construct($config = array()) {
        if (empty($config['filter_fields'])) {
            $config['filter_fields'] = array(
                'id', 'a.id',
                'title', 'a.title',
                'tourday', 'a.tourday',
                'tournight', 'a.tournight',
                'tourdescribtion', 'a.tourdescribtion',
                'tourimage', 'a.tourimage',
                'tourbrief', 'a.tourbrief',
                'tourdetail', 'a.tourdetail',
                'tourwaitin', 'a.tourwaitin',
                'tourcategories', 'a.tourcategories',
                'tourcountry', 'a.tourcountry',
                'tourplace', 'a.tourplace'
            );
        }
        parent::__construct($config);
    }

    protected function getListQuery() {
        $db = $this->getDbo();
       if(JRequest::getInt('catid')!=""){
           $pk = JRequest::getInt('catid');
       }else{
        $app = JFactory::getApplication();
      $params = $app->getParams();
      //print_r($params->get('catid'));
        $pk =$params->get('catid');
       }
        $query = $db->getQuery(true);
        $query->select(
                $this->getState(
                        'list.select', 'a.id, a.title,' .
                    
                 'a.tourday ,'.
                 'a.tournight ,'.
                 'a.tourdescribtion ,'.
                 'a.tourimage ,'.
                 'a.tourbrief ,'.
                 'a.tourdetail ,'.
                 'a.tourwaitin ,'.
                 'a.tourcategories ,'.
                 'a.tourcountry ,'.
                 'a.tourplace'
                )
        );
       //  $params = new JRegistry;
        //$params->loadString($item->params);
        // $item->params = $params;
        $query->from($db->quoteName('#__tour_tourdetail') . ' AS a');
        $query->where('(a.tourcategories IN ('.$pk.'))');
        $query->where("a.tourimage NOT LIKE ''");
        return $query;
    }

}
